#include "aboutview.h"
#include <QLocale>
#include "toolkit.h"
#include <QPainter>
#include <QMouseEvent>

enum AboutBtn
{
    BACK_AB,
    NULL_AB,
}aboutbtn(NULL_AB);

aboutView::aboutView(QWidget *parent):
    QWidget(parent),
    m_bShowUp(false),
    m_bShowDown(true),
    m_y(0),
    m_oldy(0)
{
    setGeometry(0.0,0.0,640.0,360.0);

    m_bgImage.load(":/image/about/about_bg.png");

    switch(ToolKit::m_language)
    {
    case QLocale::Chinese:
    {
        m_textImage.load(":/image/about/ch.png");
    }
        break;
    case QLocale::HongKong:
    case QLocale::Taiwan:
    {
        m_textImage.load(":/image/about/chh.png");
    }
        break;
    default:
    {
        m_textImage.load(":/image/about/en.png");
    }
        break;
    }

    m_upImage.load(":/image/about/about_up.png");
    m_downImage.load(":/image/about/about_down.png");
    m_backImage.load(":/image/about/about_back.png");
}

aboutView::~aboutView()
{

}

void aboutView::mousePressEvent(QMouseEvent *event)
{
    if(QRectF(496.0,228.0,60.0,60.0).contains(event->pos()))
    {
        if(ToolKit::m_bVoice)
            ToolKit::playSound(4);
        emit back();
    }
    else
    {
        m_oldy = event->y();
    }
}

void aboutView::mouseMoveEvent(QMouseEvent *event)
{
    m_y -= event->y() - m_oldy;
    if(0 < m_y && m_y < 940)
    {
       m_bShowUp = true;
       m_bShowDown = true;
    }
    else if(m_y <= 0)
    {
        m_y = 0;
        m_bShowUp = false;
    }
    else if(m_y >= 940)
    {
        m_y = 940;
        m_bShowDown = false;
    }

    m_oldy = event->y();
    update();
}

void aboutView::paintEvent(QPaintEvent *event)
{
    QPainter p(this);
    p.drawImage(99,41,m_bgImage);
    p.drawImage(QRectF(122.0,59.0,407.0,201.0),m_textImage,QRectF(0.0,m_y,407.0,201.0));
    p.drawImage(523,249,m_backImage);
    if(m_bShowDown)
        p.drawImage(320,258,m_downImage);
    if(m_bShowUp)
        p.drawImage(320,44,m_upImage);
}
